namespace CIS
{
    using CISLib;
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class Default : Page
    {
        protected Button cancelBtn;
        protected Image iCompany;
        protected Label lbAgreeCn;
        protected Label lbAgreeEn;
        protected Label lbTitleCn;
        protected Label lbTitleEn;
        protected Button okBtn;
        protected UserPrincipal Principal = null;

        private void cancelBtn_Click(object sender, EventArgs e)
        {
            ManageLog.InsertLog(this.Principal.SysUser.UserId, this.Principal.SysUser.LoginName, DateTime.Now, "Reject Agreement", "IP:" + base.Request.UserHostAddress + " DNS:" + base.Request.UserHostName, "");
            base.Response.Redirect("Logout.aspx", true);
        }

        private void InitializeComponent()
        {
            this.okBtn.Click += new EventHandler(this.okBtn_Click);
            this.cancelBtn.Click += new EventHandler(this.cancelBtn_Click);
            base.Load += new EventHandler(this.Page_Load);
        }

        private void okBtn_Click(object sender, EventArgs e)
        {
            ManageLog.InsertLog(this.Principal.SysUser.UserId, this.Principal.SysUser.LoginName, DateTime.Now, "Accept Agreement", "IP:" + base.Request.UserHostAddress + " DNS:" + base.Request.UserHostName, "");
            this.Page.Session.Add("IsRead", "True");
            base.Response.Redirect("DefaultFrame.aspx", true);
        }

        protected override void OnInit(EventArgs e)
        {
            this.InitializeComponent();
            base.OnInit(e);
            this.Principal = this.Context.User as UserPrincipal;
        }

        private void Page_Load(object sender, EventArgs e)
        {
            string language = this.Session["language"].ToString();
            this.SetFromImage();
            switch (language)
            {
                case "cn":
                    this.lbTitleCn.Visible = true;
                    this.lbTitleEn.Visible = false;
                    this.lbAgreeCn.Visible = true;
                    this.lbAgreeEn.Visible = false;
                    this.okBtn.Text = "我同意并接受以上条款";
                    this.cancelBtn.Text = "不同意";
                    break;

                case "en":
                    this.lbTitleCn.Visible = false;
                    this.lbTitleEn.Visible = true;
                    this.lbAgreeCn.Visible = false;
                    this.lbAgreeEn.Visible = true;
                    this.okBtn.Text = "accept the agreement";
                    this.cancelBtn.Text = "Reject";
                    break;
            }
        }

        private void SetFromImage()
        {
            switch (this.Session["language"].ToString())
            {
                case "cn":
                    this.iCompany.ImageUrl = "images/title_ConfidentialAggreement.jpg";
                    break;

                case "en":
                    this.iCompany.ImageUrl = "images/title_ConfidentialAggreementEn.jpg";
                    break;
            }
        }
    }
}

